<template>
  <div class="login">
    <el-form
      ref="loginFormRef"
      :model="loginForm"
      :rules="loginRules"
      class="login-form"
    >
      <div class="title">
        <!-- <img
          :src="imgurl"
          style="width: 30px; height: 30px; margin-right: 5px"
        /> -->
        <span>欢迎登录系统</span>
      </div>
      <el-form-item prop="username">
        <div style="height: 30px">账号</div>
        <el-input v-model="loginForm.username" type="text" auto-complete="off">
        </el-input>
      </el-form-item>
      <el-form-item prop="password">
        <div style="height: 30px">密码</div>
        <el-input
          v-model="loginForm.password"
          type="password"
          auto-complete="new-password"
          @keyup.enter.native="handleLogin"
        >
        </el-input>
      </el-form-item>
      <el-form-item>
        <el-button
          :loading="loading"
          size="medium"
          type="primary"
          style="width: 100%; border-radius: 30px; margin-top: 40px"
          @click.native.prevent="handleLogin"
        >
          <span v-if="!loading">安 全 登 录</span>
          <span v-else>登 录 中...</span>
        </el-button>
        <!-- <div style="float: right">
          <router-link class="link-type" :to="'/register'"
            >立即注册</router-link
          >
        </div> -->
      </el-form-item>
    </el-form>
    <!--  底部  -->
    <div class="el-login-footer">
      <span>Copyright ©2023 xxx有限公司</span>
    </div>
  </div>
</template>

<script>
import { setToken } from "@/utils/auth";
import { login } from "@/api/login";
export default {
  name: "Login",
  components: {},
  setup() {
    const router = useRouter();
    const loginFormRef = ref();
    const store = useStore();
    const pageData = reactive({
      loginForm: {
        username: "",
        password: "",
      },
      loading: false,
      loginRules: {
        username: [
          { required: true, trigger: "blur", message: "请输入您的账号" },
        ],
        password: [
          { required: true, trigger: "blur", message: "请输入您的密码" },
        ],
      },
    });

    const handleLogin = () => {
      const form = unref(loginFormRef);
      form.validate((valid) => {
        if (valid) {
          pageData.loading = true;
          store.dispatch("Login", pageData.loginForm).then(() => {
            pageData.loading = false;
            router.push("/");
          });
          // login("1", "1").then((res) => {
          //   pageData.loading = false;
          //   console.log("!!!!", res);
          //   setToken(res);
          //   router.push("/");
          // });
        }
      });
    };
    return {
      ...toRefs(pageData),
      handleLogin,
      loginFormRef,
    };
  },
};
</script>

<style lang="scss" scoped>
.login {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
  min-width: 1200px;
  min-height: 600px;
  background-image: url("../assets/images/login-background.jpg");
  background-size: cover;
  background-position: center center;
}
.title {
  margin: 50px 0 30px -10px;
  color: #000;
  display: flex;
  flex-direction: row;
  align-items: center;
  font-size: 20px;
}

.login-form {
  padding: 0px 100px 40px 100px;
  border-radius: 10px;
  background-color: #5b5b5b;
  background-color: rgba(0, 0, 0, 0.2);
  .el-form-item {
    width: 20vw;
    min-width: 200px;
  }
  .el-input {
    height: 30px;
    input {
      height: 30px;
      border: 0;
      border-radius: 0;
      border-bottom: 1.5px solid;
    }
  }
  // .input-icon {
  //   height: 39px;
  //   width: 14px;
  //   margin-left: 2px;
  // }
}
.login-tip {
  font-size: 13px;
  text-align: center;
  color: #bfbfbf;
}
.login-code {
  width: 33%;
  height: 38px;
  float: right;
  img {
    cursor: pointer;
    vertical-align: middle;
  }
}
.el-login-footer {
  height: 40px;
  line-height: 40px;
  position: fixed;
  bottom: 0;
  width: 100%;
  text-align: center;
  color: #fff;
  font-family: Arial;
  font-size: 12px;
  letter-spacing: 1px;
}
.login-code-img {
  height: 38px;
}
</style>
